perf: durable Columnar DELETE in-place via tombstone markers (no flush rewrite) - #367
Merged
Merged
Conversation
…h rewrite) Non-transactional Columnar deletes now write a tombstone marker over the record's 4-byte length prefix (negative slot size) instead of queueing a flush-time full-file rewrite, so DELETE survives a reopen in O(delete). --pk harness DELETE: ~18.6K ops/s -> ~64K (legacy) / ~81K ops/s (fixed-width), back on par with UPDATE. - IStorage.TombstoneRecord (default false) + Storage implementation (read slot size, write -slotSize marker, evict page cache). - Every raw record enumerator/compactor skips negative prefixes: Storage.ReadAllRecords, AppendOnlyEngine.GetAllRecords + CompactTable, Table.Scanning/CRUD/ParallelScan. - CompactTable broke on a negative prefix, which made the ULID-migration compaction (delete+insert then CompactStorage) write an empty file; it now skips tombstones so migration stays correct. - Transactional deletes are NOT tombstoned at delete time (a marker would survive a rollback that restores the row in the PK index); they are physically removed by the post-commit flush/dispose compaction against the current PK, keeping the rollback-safe semantics of #366. - Tombstone space is reclaimed by the tombstone-aware CompactStorage/CompactTable (explicit, auto-compact threshold, ULID migration). CHANGELOG updated.
|
This was referenced Sep 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Why
Master #366 made Columnar DELETE durable by compacting at flush/dispose, but the rewrite cost dropped
--pkDELETE to ~18.6K ops/s (0.54s per 10K deletes on a ~100K-row table).This PR makes the durable delete in-place: a tombstone marker is written over the record's 4-byte length prefix (negative slot size), and every raw record enumerator/compactor skips the slot. DELETE survives a reopen in O(delete) — no flush-time rewrite.
Root cause this PR fixes
The earlier tombstone attempt was reverted because the ULID-migration flow (
delete + insert→CompactStorage) produced an empty.dat(rows=1,filelen=0). Cause found:AppendOnlyEngine.CompactTabledidbreakon any non-positive prefix, so the first tombstone stopped the walk and nothing active was rewritten. It now skips negative prefixes like every other enumerator.Rollback safety
A tombstone written before a transaction commits would survive a rollback that restores the row in the PK index. Transactional deletes are therefore not tombstoned at delete time; they are physically removed by the post-commit flush/dispose compaction against the current PK — the rollback-safe semantics of #366. Non-transactional DELETE (the measured hot path) never pays that rewrite.
Measured (
--pkharness, DELETE 10K of ~100K rows)DELETE is again on par with UPDATE (FW UPDATE ~86.7K ops/s). Tombstone space is reclaimed by the tombstone-aware
CompactTable/CompactStorage(explicit, auto-compact threshold, ULID migration).Validation
SharpCoreDB.Testssuite (Debug + Release/CI filter): green (1656 tests, incl.LegacyUlidMigrationTests, ULID, bulk-delete, reopen, fixed-width, transaction suites).Category!=Debug&Category!=Manual&Category!=Performance):SharpCoreDB.Tests,SharpCoreDB.VectorSearch.Tests,SharpCoreDB.EntityFrameworkCore.Tests,SharpCoreDB.Functional.Linq2DB.Tests— all EXIT=0.